package dbtools;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBDerbyDatabase extends DBDatabase{

	private String derbyDBAddr;
	
	public DBDerbyDatabase (String dbAddr){
		this.derbyDBAddr = dbAddr;
		String driver = "org.apache.derby.jdbc.EmbeddedDriver";
		try {
			Class.forName(driver).newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} 
	}
	
	private Connection createConnection() throws SQLException{
		
		Connection conn = DriverManager.getConnection("jdbc:derby:"+derbyDBAddr);
		return conn;
	}
	
	@Override
	public DBTransaction createTransaction() throws SQLException {
		DBTransaction trans = new DBTransaction(createConnection(),this);
		return trans;
	}

}
